package com.nowcoder.Offer.Stack;


import java.util.Stack;

/**
 * O(1)时间得到最小值的栈
 */
public class MinStack {

    Stack<Integer> DataStack = new Stack<>();
    Stack<Integer> MinStack = new Stack<>();

    public void push(int node) {
        DataStack.push(node);

        if(MinStack.isEmpty() || node < MinStack.peek())
            MinStack.push(node);
    }

    public void pop() {
        int topNode = DataStack.pop();

        if(topNode == MinStack.peek())
            MinStack.pop();
    }

    public int top() {
        return DataStack.peek();
    }

    public int min() {
        return MinStack.peek();
    }

}
